﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Services_MaintDispatch : System.Web.UI.Page
{
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        txtKdate.Attributes.Add("onclick", "SelectDate('txtKdate')");
        txtJdate.Attributes.Add("onclick", "SelectDate('txtJdate')");
        if (!IsPostBack)
        {
            initData();
            lblPath.Text = f.getModuleidAdd(Request["moduid"]);

          
        }
    }

    private void initData() 
    {

        string sql = "select *,Convert(char(10),MaintDate,120) as Date,StaffName from CS_Mailadd as a join CS_Staff as b on a.userid=b.StaffId where isWC=1  order by Maintaddid desc";
     

        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
     
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {


        string sql = "select *,Convert(char(10),dispTime,120) as Date,Convert(char(10),MaintDate,120) as Date1 from CS_Mailadd where ismail=1 and isWC=1 ";
        if (!string.IsNullOrEmpty(txttel.Text))
        {
            sql += " and Guesttel like '%" + Common.FormatParameter(txttel.Text) + "%'";
        }
        if (!string.IsNullOrEmpty(txtmol.Text))
        {
            sql += " and comidSpe like '%" + Common.FormatParameter(txtmol.Text) + "%'";
        }
        if (!string.IsNullOrEmpty(txtSalesCode.Text))
        {
            sql += " and SalesCode like '%" + Common.FormatParameter(txtSalesCode.Text) + "%'";
        }
        if (!string.IsNullOrEmpty(txtGuest.Text))
        {
            sql += " and Guestname like'" + Common.FormatParameter(txtGuest.Text) + "%'";
        }
        if (!string.IsNullOrEmpty(txtKdate.Text) && !string.IsNullOrEmpty(txtJdate.Text.Trim()))
        {
            sql += " and MaintDate >='" + Common.FormatParameter(txtKdate.Text) + " 00:00:00' and MaintDate<='" + Common.FormatParameter(txtJdate.Text) + " 23:59:59'";
        }
        sql += " order by Maintaddid desc";
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
    }
    protected void linkPrint_Click(object sender, EventArgs e)
    {
        string id = (sender as LinkButton).CommandArgument;
        ZSql zs = new ZSql();
        zs.Open("select * from CS_Mailadd where Maintaddid=" + id);
        ClientScript.RegisterStartupScript(typeof(Page), "aa", "PrintData('" + id + "')", true);
        
    }
    protected void linkedit_Click(object sender, EventArgs e)
    {
        string id = (sender as LinkButton).CommandArgument;
        Response.Redirect("DispatchAdd.aspx?id=" + id + "&moduid=" + Request["moduid"] + "&action=edit");
    }
    protected void btndel_Click(object sender, EventArgs e)
    {
        ZSql del = new ZSql();
        int n = 0;
        if (this.GvData.Rows.Count > 0)
        {
            for (int i = 0; i < GvData.Rows.Count; i++)
            {
                CheckBox ck = GvData.Rows[i].Cells[9].FindControl("chkDelete") as CheckBox;
                if (ck.Checked)
                {

                    del.Open("delete CS_Mailadd  where Maintaddid=" + this.GvData.Rows[i].Cells[0].Text);
                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('删除成功');", true);

                }
                else
                {
                    n++;
                }

                if (n == this.GvData.Rows.Count)
                {

                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('至少应选择一项')", true);
                }

            }
        }
    }
    protected void addWX_Click(object sender, EventArgs e)
    {

    }
}
